﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _MetalSlug.MyCharacters.Characters;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace _MetalSlug.MyCharacters.HeroDisplayer
{
    public class Displayer:VisibleGameEntity
    {
        public const int DelayShotTime = 5;
        public enum RESOURCE_FACE
        {
            LEFT,
            RIGHT
        }

        Boolean isAlive;

        public Boolean IsAlive
        {
            get { return isAlive; }
            set 
            { 
                isAlive = value;               
            }
        }

        protected HeroBody body;
        public HeroBody Body
        {
            get { return body; }
            set { body = value; }
        }

        protected HeroFoot foot;
        public HeroFoot Foot
        {
            get { return foot; }
            set { foot = value; }
        }

        Color colorDisplay;

        public Color ColorDisplay
        {
            get { return colorDisplay; }
            set
            {
                colorDisplay = value;
                if (ColorDisplay == Color.White)
                {
                    DelayShot = -1;
                }
                else
                {
                    DelayShot = 0;
                }
            }
        }

        int delayShot;

        public int DelayShot
        {
            get { return delayShot; }
            set { delayShot = value; }
        }

        long time;

        public long Time
        {
            get { return time; }
            set { time = value; }
        }

        public Displayer(Vector2 _Size)
        {
            IsAlive = true;
            Size = _Size;
            Time = 0;
        }

        public override void Update(GameTime gameTime)
        {
            Time++;
            if(IsAlive)
            {
                if (DelayShot != -1)
                {
                    DelayShot++;
                    if (DelayShot > DelayShotTime)
                    {
                        ColorDisplay = Color.White;
                    }
                }
            }

            SetTopLeft(TopLeft);
            if (Time % 5 == 0)
            {
                Foot.nextFrame();
            }

            if (Time % 10 == 0)
            {
                Body.nextFrame();
            }

            
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            if(IsAlive)
            {
                Foot.Draw(spriteBatch);
            }

            Body.Draw(spriteBatch);
            
        }

        public void SetTopLeft(Vector2 newPosition)
        {
            TopLeft = newPosition;
            Body.TopLeft = newPosition;
            Foot.TopLeft = newPosition;
        }

        public void SetFlip(MySprite.FLIPABLE FlipState)
        {
            Body.Flip = FlipState;
            Foot.Flip = FlipState;
        }

        public Boolean isExtinct()
        {
            if(!IsAlive && Body.isLastFrame())
            {
                return true;
            }

            return false;
        }

        public Boolean isEndShooting()
        {
            if(Body.CurrentActivity == MyCharacter.CURRENT_ACTIVITY.SHOOT && Body.isLastFrame())
            {
                return true;
            }
            return false;
        }

        
    }
}
